﻿using Axis.Dao.Research;
using Axis.Web.Administrator.Global;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Text;
using Axis.BusinessObject.Research;
using System.Text.RegularExpressions;
using Axis.BusinessObject.Core;

namespace Axis.Web.Views.Project
{
    public partial class Project : System.Web.UI.Page
    {
        CMemberList member = new CMemberList();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string projectID = "0";
                if (Request.QueryString["ProjectID"] != null)
                    projectID = Request.QueryString["ProjectID"];
                if (Page.RouteData.Values["ProjectID"] != null)
                    projectID = Page.RouteData.Values["ProjectID"] as string;
                ltrProjectListItem.Text = GetProjectList(projectID);

            }
        }
        protected string GetProjectList(string projectID)
        {
           
            if (Session["MEMBERINFO"] != null)
                member = Session["MEMBERINFO"] as CMemberList;

            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement("InputValue");
            doc.AppendChild(root);
            root.SetAttribute("Action", "GET");
            root.SetAttribute("UserID", member.ID.ToString());
            root.SetAttribute("SecrectToken", member.SecrectToken);
            root.SetAttribute("PageIndex", "1");
            root.SetAttribute("RowsPerPage", "999");
            root.SetAttribute("ID", projectID);
            string inputValue = root.OuterXml;
            return GetProjectListHTML(inputValue);

        }
        public string GetProjectListHTML(string inputValue)
        {
            CProjectUI UI = new CProjectUI(member);
            StringBuilder ret = new StringBuilder();
            IList<CProject> list = UI.GetProject(inputValue);
            if (list != null && list.Count > 0)
            {
                foreach (CProject project in list)
                {
                    ret.Append(UI.GetProjectHTML(project));
                }
                CProject item = list[0];

                try
                {
                    string Pattent = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
                + "<meta name=\"description\" content=\"{0}.\" />"
                + "<meta name=\"keywords\" content=\"{1}\" />  "
                 + "<meta property=\"fb:admins\" content=\"100000866764550113\" />"
                    + "<meta  property=\"og:image\" content =\"{2}\" itemprop=\"thumbnailUrl\"/>  ";
                    string description = "";
                    if (item.Description != null)
                    {
                        Regex regex = new Regex("(<.*?>\\s*)+", RegexOptions.Singleline);
                        description = regex.Replace(item.Description, " ").Trim();
                    }
                    HeaderPage.Text = string.Format(Pattent, description, item.Name, "http://6sao.vn" + item.Image1);
                    TitlePage.Text = item.Name + "| Trúng thưởng | Quà tặng miễn phí | Khảo sát trực tuyến";
                }
                catch (Exception ex)
                {

                }
            }
            return ret.ToString();
        }
    }
}